<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增教室')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-classRoom-add">
            <!--<div class="form-group" th:if="${@permission.hasPermi('system:superAdmin:opt')} != 'hidden'">
                <label class="col-sm-3 control-label is-required">所属租户：</label>
                <div class="col-sm-8">
                    <select name="tenantId" id="tenantId"  class="form-control" onchange="loadCampus()">
                        <option th:each="t : ${tenantList}" th:text="${t.tenantName}" th:value="${t.tenantId}"></option>
                    </select>
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">所属分校：</label>
                <div class="col-sm-8">
                    <select name="campusId" id="campusId" required class="form-control">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">教室名称：</label>
                <div class="col-sm-8">
                    <input  id="name" name="name" class="form-control" type="text" required maxlength="30"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">容纳人数：</label>
                <div class="col-sm-8">
                    <input id="nums" name="nums" class="form-control" type="text" required maxlength="6"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">多媒体教室：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <input type="radio" id="roomType1" name="roomType" value="1">
                        <label for="roomType1">是</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="roomType2" name="roomType" value="0" checked>
                        <label for="roomType2">否</label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">位置：</label>
                <div class="col-sm-8">
                    <div class="col-sm-4">
                        <input id="address1" name="address1" class="form-control" type="text" placeholder="请输入楼层" maxlength="30"/>
                    </div>
                    <div class="col-sm-4">
                        <input id="address2" name="address2" class="form-control" type="text" placeholder="请输入室号" maxlength="30"/>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea id="remark" name="remark" class="form-control" maxlength="300"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        var prefix = ctx + "system/classRoom"
        $("#form-classRoom-add").validate({
            onkeyup: false,
            rules:{
                name:{
                    remote: {
                        url: ctx + "system/classRoom/checkNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "name" : function() {
                                return $.common.trim($("#name").val());
                            },
                            "campusId" : function() {
                                return $.common.trim($("#campusId").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                nums:{
                    digits:true
                },
            },
            messages: {
                "name": {
                    remote: "名称已存在！"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-classRoom-add').serialize());
            }
        }

        $(function() {
            loadCampus();
        })

        function loadCampus() {
            var tenantId = $("#tenantId").val();
            $.ajax({
                type: "POST",
                url: "/system/common/tenantCampus",
                data: {tenantId, tenantId},
                async: false,
                success: function(data) {
                    $("#campusId").empty();
                    var obj = data.rows;
                    for (var i in obj) {
                        $("#campusId").append("<option value=\"" + obj[i].id + "\">" + obj[i].name + "</option>");
                    }
                }
            })
        }
    </script>
</body>
</html>